Skip to content

refactor: 提升代码质量 - 类型安全、消除重复、修复数据转换#866

Closed
Copilot wants to merge 4 commits intodev-dl-rustfrom
copilot/sub-pr-864
Closed

refactor: 提升代码质量 - 类型安全、消除重复、修复数据转换#866
Copilot wants to merge 4 commits intodev-dl-rustfrom
copilot/sub-pr-864

Conversation

Copy link

Copilot AI commented Feb 11, 2026

代码审查发现类型安全问题、数据转换错误和代码重复。本次重构修复这些问题并提升整体代码质量。

修复数据转换错误

  • processMusicList: 恢复 duration 秒转毫秒和 size 字节保留(前端需要原始字节数供 formatFileSize 处理)
  • Local/layout.vue: 修复 allMusicSize 计算(字节 → GB)
// 之前:删除了关键转换,破坏前端显示
return { ...track, name: track.title, cover, quality: track.bitrate ?? 0 };

// 之后:保持正确的数据格式
return {
  ...track,
  name: track.title,
  cover,
  size: track.size,           // 字节数,供 formatFileSize 处理
  duration: track.duration * 1000,  // 转为毫秒
  quality: track.bitrate ?? 0,
};

消除 any 类型,增强类型安全

  • 定义明确类型: ArtistProcessedMusicTrackScanEvent(含 Progress/Batch/End 子类型)
  • 移除 getArtistNamesany 参数: 使用 Artist | Artist[]
  • 扫描回调事件类型化: (err, event: ScanEvent | null) => void
// 之前:类型不安全
export const getArtistNames = (artists: any): string[] => {
  // ...
}

// 之后:明确类型定义
type Artist = string | { name?: string };
export const getArtistNames = (artists: Artist | Artist[]): string[] => {
  // ...
}

消除代码重复

创建 utils/paths.ts 统一路径管理,消除 ipc-file.tsLocalMusicService 中的重复 getCoverDir 实现(-15 行):

// utils/paths.ts - 单一来源
export const getCoverDir = (): string => {
  return getLocalDataPaths().coverDir;
};

// ipc-file.ts & LocalMusicService.ts - 复用
import { getCoverDir } from "../utils/paths";

其他优化

  • 提取 LocalMusicDB.escapeLike 为私有方法
  • 移除不必要的空回调 () => {}
  • 完善函数返回类型标注

质量验证: ✅ Code Review (0 issues) | ✅ CodeQL (0 alerts)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Refactor download manager for Rust directory scanning and taskbar color refactor: 提升代码质量 - 类型安全、消除重复、修复数据转换 Feb 11, 2026
Copilot AI requested a review from imsyy February 11, 2026 06:31
@imsyy
Copy link
Owner

imsyy commented Feb 11, 2026

@copilot 你写的也是 💩 😆

@imsyy imsyy closed this Feb 11, 2026
@apoint123 apoint123 deleted the copilot/sub-pr-864 branch February 22, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants